package com.mwumz.third.common;

import org.apache.ibatis.session.RowBounds;

/**
 * @Author: wumz
 * @Date: 2020/7/2 15:07
 * @Version 1.0
 */
public class Page {
    private Long totalCount;
    private Long pageIndex;
    private Long pageSize;

    public Page() {
        this.pageIndex = 1L;
        this.pageSize = 10L;
    }

    public Page(Long pageIndex) {
        this();
        pageIndex = pageIndex == null ? 1L : pageIndex;
        this.pageSize = 10L;
        this.pageIndex = pageIndex;
    }

    public Page(Long pageIndex, Long pageSize) {
        pageIndex = pageIndex == null ? 1L : pageIndex;
        pageSize = pageSize == null ? 10L : pageSize;
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
    }

    public Long getPageSize() {
        return this.pageSize = this.pageSize < 1L ? 10L : this.pageSize;
    }

    public void setPageSize(Long pageSize) {
        pageSize = pageSize == null ? 10L : pageSize;
        this.pageSize = pageSize;
    }

    public Long getPageIndex() {
        return this.pageIndex < 1L ? 1L : this.pageIndex;
    }

    public void setPageIndex(Long pageIndex) {
        pageIndex = pageIndex == null ? 1L : pageIndex;
        this.pageIndex = pageIndex;
    }

    public Long getTotalCount() {
        return this.totalCount;
    }

    public void setTotalCount(Long totalCount) {
        this.totalCount = totalCount;
    }

    public Long getPageCount() {
        return this.totalCount % this.pageSize > 0L ? this.totalCount / this.pageSize + 1L : this.totalCount / this.pageSize;
    }

    public RowBounds toRowBounds() {
        return new RowBounds(this.pageIndex > 0L ? (int)((this.pageIndex - 1L) * this.pageSize) : 0, this.pageSize > 0L ? this.pageSize.intValue() : 0);
    }

    public String toString() {
        return "Page{totalCount=" + this.totalCount + ", pageIndex=" + this.pageIndex + ", pageSize=" + this.pageSize + '}';
    }
}
